﻿/* Update */
$(document).ready(function () {
    if ($("#_txtdrugareaupdatedate") != null)
        $("#_txtdrugareaupdatedate").datepicker({ dateFormat: 'dd/mm/yy' });
});

function ClientSideViewDrugAreaInfo() {
    if (!$("#_locationsel").length) {
        alert('Bạn phải chọn địa phương quản lý');
        return;
    }
    var LocationType = $("#_locationLevelTypeSelect").val();
    var mes;
    if (LocationType == '4')
        mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideRenderDrugAreaCurrentInfo($("#_locationsel").val()).value;
    if (LocationType == '3')
        mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideRenderDistrictCurrentInfo($("#_locationsel").val()).value;
    if (LocationType == '2')
        mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideRenderProvinceCurrentInfo($("#_locationsel").val()).value;

    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", ""));
        return;
    }
    $("#drugareanumberstatus").html(mes);
}

function ClientSideShowUpdateDrugAreaInfo(LocationCode) {
    var mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideRenderUpdateDrugArea(LocationCode).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", ""));
        return;
    }
    $("#drugareanumberstatus").html(mes);
    $("#_txtdrugareaupdatedate").datepicker({ dateFormat: 'dd/mm/yy' });
}

function ClientSideUpdateDrugAreaInfo(LocationCode) {
    _txtdrugareaupdatedate = document.getElementById("drpDay_txtdrugareaupdatedate").options[document.getElementById("drpDay_txtdrugareaupdatedate").selectedIndex].value + '/' + document.getElementById("drpMonth_txtdrugareaupdatedate").options[document.getElementById("drpMonth_txtdrugareaupdatedate").selectedIndex].value + '/' + document.getElementById("drpYear_txtdrugareaupdatedate").options[document.getElementById("drpYear_txtdrugareaupdatedate").selectedIndex].value;
    var mes = Portal.SODC.IDIS.DrugAreaInsert.ServerSideUpdateDrugAreaInfo(LocationCode, $("#_txtdrugareapoint").val(), $("#_txtdrugareahighpoint").val(), _txtdrugareaupdatedate).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", ""));
        return;
    }
    alert(mes);
}
function ClientSideProvinceUpdateDrugAreaInfo(LocationCode) {
    _txtdrugareaupdatedate = document.getElementById("drpDay_txtdrugareaupdatedate").options[document.getElementById("drpDay_txtdrugareaupdatedate").selectedIndex].value + '/' + document.getElementById("drpMonth_txtdrugareaupdatedate").options[document.getElementById("drpMonth_txtdrugareaupdatedate").selectedIndex].value + '/' + document.getElementById("drpYear_txtdrugareaupdatedate").options[document.getElementById("drpYear_txtdrugareaupdatedate").selectedIndex].value;
    var mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideUpdateProvinceDrugAreaCurrentInfo(LocationCode, $("#_txtdrugarealine").val(), _txtdrugareaupdatedate).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", ""));
        return;
    }
    alert(mes);
}

/* REGION: DrugAreaMgr 
function SwitchLevelType(LevelLocationType) {
    if ($('#_filterByParentLocation').attr('checked')) {
        $("#_locationSelect").html(Portal.SODC.IDIS.DrugAreaMgr.ServerSideRenderDrugAreaLocationSelect(LevelLocationType).value);
    }
    else {
        $("#_locationSelect").html(Portal.SODC.IDIS.DrugAreaMgr.ServerSideRenderDrugAreaLocationSelect(LevelLocationType).value);
        if (LevelLocationType == "0")
            $("#drugareanumberstatus").html("");
    }
}
*/
function DeletePrecintRecord(RecordID) {
    var mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideDeletePrecintRecord(RecordID).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", ""));
        return;
    }
    alert(mes);
}
function DeleteProvinceRecord(RecordID) {
    var mes = Portal.SODC.IDIS.DrugAreaMgr.ServerSideDeleteProvinceRecord(RecordID).value;
    if (mes.indexOf("ERROR") != -1) {
        alert(mes.replace("ERROR:", ""));
        return;
    }
    alert(mes);
}

function fireParentForm(LevelLocationType, WebpartId, PermissionCode) {
        if (LevelLocationType == "0") {
            $("#_controlpanel").hide();
        }
        else if (LevelLocationType == "1")
            $("#_controlpanel").hide();
        else
            $("#_controlpanel").show();
}